<div class="open-form">
    <div class="open-model">
        <div class="open-auto">
            <button class="layui-btn" id="isCheckFun" style="border-radius: 4px;margin-bottom: 10px">确认选择</button>
            <table id="orderFormTableTable"></table>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
        </div>
    </div>
</div>
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'tree', 'laytpl'], async function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        const  nowData={...parentData}
        let cacheList = nowData.cacheList
        table.render({
            elem: '#orderFormTableTable',
            url: config.base + `enterprise/product/admin/productDetailWMS/list`,
            where: {notInListIds: nowData.notInListIds},
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'skuCode', align: 'center', title: '物料料号'}
                , {field: 'skuName', align: 'center', title: '产品名称',}
                , {field: 'skuSpec', align: 'center', title: '规格码',}
                , {field: 'productTypeName', align: 'center', title: '产品类型',}
                , {field: 'mainUnitName', align: 'center', title: '单位'}
                , {field: 'haveQuantity', align: 'center', title: '库存数',}
                , {field: 'suggestionMinPrice', align: 'center', title: '建议最低单价'}
                , {field: 'minPrice', align: 'center', title: '建议单价'},
            ]],
            done: function () {
                if (nowData.cacheList.length > 0) {
                    table.cache['orderFormTableTable'].forEach((item, index) => {
                        const isSelected = parentData.cacheList.some(checkItem => checkItem.productDetailId === item.id);
                        if (isSelected) {
                            item["LAY_CHECKED"] = true
                            $('div.layui-table-body input[name="layTableCheckbox"]:eq(' + (index) + ')').prop('checked', true);
                            $('div.layui-table-body input[name="layTableCheckbox"]:eq(' + (index) + ')').next().addClass('layui-form-checked');

                        }
                    });
                }
                form.render('checkbox');
            }
        });
        // const res = await admin.reqPro(`enterprise/product/admin/productDetailWMS/list`, {})
        // table.reload('orderFormTableTable', {
        //     data: res.data.map(v => {
        //         delete v.id
        //         return v
        //     })
        // })
        $('#isCheckFun').click(() => {
            var checkStatus = table.checkStatus('orderFormTableTable'); // 'demo'是表格的ID
            var data = checkStatus.data;  // 选中的数据
            if (typeof parent.layui !== 'undefined') {
                childData.list = data.map(v => {
                    v.customerSkuItem = v.cusSkuCode
                    v.customerSkuName = v.cusProductName
                    v.customerSpecCode = v.cusProductSpec
                    v.productDetailId = v.id;
                    return v
                })
                console.log('childData', data)
                layer.close(parentData.zindex); // 关闭指定的弹窗
            }
        })

    })
</script>